//
//  MeInfoMainCell.m
//  MPTLive
//
//  Created by HouGeng on 16/1/28.
//  Copyright © 2016年 Jeakin. All rights reserved.
//

#import "MeInfoMainCell.h"
#import "MPTTool.h"

#define Kong (15)

@interface MeInfoMainCell()

@property (nonatomic, strong) TPImageView *imageVHead;

/// 录播时间
@property (nonatomic, strong) TPLabel *labTime;

/// 直播文字
@property (nonatomic, strong) TPLabel *labLive;

@property (nonatomic, strong) TPLabel *labNeiNong;

/// 时间和观看次数
@property (nonatomic, strong) TPLabel *labTimeAndNumber;

/// 按钮
@property (nonatomic, strong) TPButton *butDian;


@end

@implementation MeInfoMainCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        /// 封面
        _imageVHead = [TPImageView getWithFrame:CGRectMake(Kong, Kong, 211/ 2, 166 / 2)];
        _imageVHead.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_imageVHead];
        
        /// 时间
        _labTime = [TPLabel getWithFrame:CGRectMake(_imageVHead.frame.size.width - 50,
                                                       _imageVHead.frame.size.height - 16,
                                                       50,
                                                       16)
                                       text:@""
                                  textColor:[UIColor whiteColor]
                                   textFont:[UIFont fontWithName:@"FZLTXHK--GBK1-0" size:9.0f]
                              textAlignment:NSTextAlignmentCenter];
        _labTime.backgroundColor = RGBAAllColor(0x000000, 0.5);
        [self.imageVHead addSubview:_labTime];
        
        /// 直播文字
        _labLive = [TPLabel getWithFrame:CGRectMake(0,
                                                    _imageVHead.frame.size.height - 16,
                                                    _imageVHead.frame.size.width,
                                                    16)
                                    text:@""
                               textColor:[UIColor whiteColor]
                                textFont:[UIFont fontWithName:@"FZLTXHK--GBK1-0" size:9.0f]
                           textAlignment:NSTextAlignmentCenter];
        _labLive.backgroundColor = RGBAAllColor(0xF04433, 0.5);
        [self.imageVHead addSubview:_labLive];
        
        /// 标题
        _labNeiNong = [TPLabel getWithFrame:CGRectMake(CGRectGetMaxX(_imageVHead.frame)+10,
                                                       Kong + 5,
                                                       screenW - 32 - CGRectGetMaxX(_imageVHead.frame)- 10,
                                                       35)
                                       text:@""
                                  textColor:RGBAllColor(0x666666)
                                   textFont:[UIFont fontWithName:@"FZLTXHK--GBK1-0" size:13.0f]
                              textAlignment:NSTextAlignmentLeft];
        _labNeiNong.numberOfLines = 0;
        [self.contentView addSubview:_labNeiNong];
        
        /// 时间
        _labTimeAndNumber = [TPLabel getWithFrame:CGRectMake(CGRectGetMaxX(_imageVHead.frame)+10,
                                                       CGRectGetMaxY(_labNeiNong.frame) + 10,
                                                       screenW - 32 - CGRectGetMaxX(_imageVHead.frame)+10,
                                                       30)
                                       text:@""
                                  textColor:RGBAllColor(0x282828)
                                   textFont:[UIFont fontWithName:@"FZLTXHK--GBK1-0" size:12.0f]
                              textAlignment:NSTextAlignmentLeft];
        [self.contentView addSubview:_labTimeAndNumber];
        
        
        TPImageView *imagev = [TPImageView getWithFrame:CGRectMake(screenW - 24, Kong, 4, 18) image:[UIImage imageNamed:@"gengduo"]];
        [self.contentView addSubview:imagev];
        /// 点
        _butDian = [TPButton getWithFrame:CGRectMake(screenW - 50, 0, 50, 98) target:self action:@selector(butDianClicked)];
        [self.contentView addSubview:_butDian];
    }
    return self;
    
}

- (void)setDicData:(NSDictionary *)dicData
{
    if (_dicData != dicData)
    {
        _dicData  = dicData;
        
        NSDictionary *dic = _dicData[@"channel"][@"pic"];
        /// 封面
        NSString *str = [NSString stringWithFormat:@"%@%@",dic[@"base"],dic[@"m"]];
        [_imageVHead sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:nil];
        
        if ([_dicData[@"channel"][@"liveStatus"] integerValue] == 2)
        {
            _labTime.hidden = NO;
            _labLive.hidden = YES;
            /// 时长
            _labTime.text = _dicData[@"channel"][@"ext"][@"lengthNice"];
        }
        else
        {
            _labTime.hidden = YES;
            _labLive.hidden = NO;
            _labLive.text = @"正在直播";
        }

        /// 标题
        if (ZB_Str_Is_Valid(_dicData[@"channel"][@"ext"][@"t"]))
        {
            _labNeiNong.text = _dicData[@"channel"][@"ext"][@"t"];
        }
        else
        {
            NSString *strName = [NSString stringWithFormat:@"%@的直播",_dicData[@"channel"][@"ext"][@"owner"][@"nick"]];
            _labNeiNong.text = strName;
        }
        
        [_labNeiNong sizeToFit];
        _labNeiNong.frame = CGRectMake(CGRectGetMaxX(_imageVHead.frame)+10,
                                                       Kong + 5,
                                                       screenW - 32 - CGRectGetMaxX(_imageVHead.frame)- 10,
                                                       _labNeiNong.frame.size.height);
                       
        _labTimeAndNumber.frame = CGRectMake(CGRectGetMaxX(_imageVHead.frame)+10,
                                             CGRectGetMaxY(_labNeiNong.frame) + 10,
                                             screenW - 32 - CGRectGetMaxX(_imageVHead.frame)+10,
                                             11);
        
        if ([_dicData[@"channel"][@"liveStatus"] integerValue] == 2)
        {
            NSString *strRen = [MPTTool getNumWith:[_dicData[@"channel"][@"stat"][@"ucnt"] integerValue]];
            _labTimeAndNumber.text = [NSString stringWithFormat:@"%@次观看·%@", strRen,_dicData[@"channel"][@"ext"][@"finishTimeNice"]];
        }
        else
        {
            
            NSString *strRen = [MPTTool getNumWith:[_dicData[@"channel"][@"stat"][@"ucnt"] integerValue]];
            NSString *strLike = [MPTTool getNumWith:[_dicData[@"channel"][@"stat"][@"mcnt"] integerValue]];
            _labTimeAndNumber.text = [NSString stringWithFormat:@"%@在看·%@赞", strRen,strLike];
        }
    }
}

- (void)butDianClicked
{
    if (self.block)
    {
        self.block(_indexpath);
    }
}

+ (CGFloat)GetHeight
{
    return 98.0f;
}

@end
